﻿using System.Data.Entity;
using System.Linq;
using SmesharikiMVC.Models.VideoCollection;

namespace SmesharikiMVC.Models
{
    public class VideoCollectionInitializer : DropCreateDatabaseAlways<VideoCollectionContext>
    {
        protected override void Seed(VideoCollectionContext context)
        {
            //create real video albums

            //Забытая история   2004
            context.Albums.Add(new VideoAlbum
                                        {
                                            //VideoAlbumID = 1,
                                            AlbumName = "Забытая история",
                                            YearIssued = 2004,
                                            IconUrl = "/Content/images/albums/dvd01.jpg"
                                        });

            //1. Забытая история	010
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 10,
                                            VideoTitle = "Забытая история",
                                            VideoDescription = "",
                                            YoutubeGuid = "-DzwOFVaMmQ",
                                            IconUrl = "/Content/images/albums/dvd01/zabytaya-istoria.jpg",
                                        });

            //2. День рождения Нюши	019
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 19,
                                            VideoTitle = "День рождения Нюши",
                                            VideoDescription = "",
                                            YoutubeGuid = "wvU2Y946C58",
                                            IconUrl = "/Content/images/albums/dvd01/den-rozhdenia-nyushi.jpg",
                                        });
            //3. Скамейка	001
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 1,
                                            VideoTitle = "Скамейка",
                                            VideoDescription = "",
                                            YoutubeGuid = "-W2tJmIJltg",
                                            IconUrl = "/Content/images/albums/dvd01/skameyka.jpg",
                                        });
            //4. Железная няня	006
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 6,
                                            VideoTitle = "Железная няня",
                                            VideoDescription = "",
                                            YoutubeGuid = "odbwz_86Xvg",
                                            IconUrl = "/Content/images/albums/dvd01/zheleznay-nyanya.jpg",
                                        });
            //5. Биография зонтика	016
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 16,
                                            VideoTitle = "Биография зонтика",
                                            VideoDescription = "",
                                            YoutubeGuid = "rqAMbxbXr4c",
                                            IconUrl = "/Content/images/albums/dvd01/biografia-zontika.jpg",
                                        });

            //6. Телеграф	013
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 13,
                                            VideoTitle = "Телеграф",
                                            VideoDescription = "",
                                            YoutubeGuid = "B6qZlPXe_a4",
                                            IconUrl = "/Content/images/albums/dvd01/telegraf.jpg",
                                        });
            //7. Коллекция	014
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 14,
                                            VideoTitle = "Коллекция",
                                            VideoDescription = "",
                                            YoutubeGuid = "wC-mrwnfQZ0",
                                            IconUrl = "/Content/images/albums/dvd01/kollektsia.jpg",
                                        });
            //8. Ля	017
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 17,
                                            VideoTitle = "Ля",
                                            VideoDescription = "",
                                            YoutubeGuid = "qpw-7O72DP8",
                                            IconUrl = "/Content/images/albums/dvd01/lya.jpg",
                                        });

            //Событие века  2004
            context.Albums.Add(new VideoAlbum
                                        {
                                            //VideoAlbumID = 2,
                                            AlbumName = "Событие века",
                                            YearIssued = 2004,
                                            IconUrl = "/Content/images/albums/dvd02.jpg"
                                        });

            //1. Новые зубы Кроша	024
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 24,
                                            VideoTitle = "Новые зубы Кроша",
                                            VideoDescription = "",
                                            YoutubeGuid = "7F6eE0w4SWE",
                                            IconUrl = "/Content/images/albums/dvd02/novye-zuby-krosha.jpg",
                                        });
            //2. Полёты во сне и наяву	021
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 21,
                                            VideoTitle = "Полёты во сне и наяву",
                                            VideoDescription = "",
                                            YoutubeGuid = "38a0f-fXZCc",
                                            IconUrl = "/Content/images/albums/dvd02/polety-vo-sne-i-nayavu.jpg",
                                        });
            //3. Событие века	022
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 22,
                                            VideoTitle = "Событие века",
                                            VideoDescription = "",
                                            YoutubeGuid = "pCdly8Bm5YY",
                                            IconUrl = "/Content/images/albums/dvd02/sobytie-veka.jpg",
                                        });

            //4. Энергия храпа	005
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 5,
                                            VideoTitle = "Энергия храпа",
                                            VideoDescription = "",
                                            YoutubeGuid = "2s2pM5aAfBc",
                                            IconUrl = "/Content/images/albums/dvd02/energia-hrapa.jpg",
                                        });
            //5. Некультурный	009
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 9,
                                            VideoTitle = "Некультурный",
                                            VideoDescription = "",
                                            YoutubeGuid = "DYgaq4lJd00",
                                            IconUrl = "/Content/images/albums/dvd02/nekulturnyi.jpg",
                                        });
            //6. Гольф	020
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 20,
                                            VideoTitle = "Гольф",
                                            VideoDescription = "",
                                            YoutubeGuid = "D25OYJ4hdys",
                                            IconUrl = "/Content/images/albums/dvd02/golf.jpg",
                                        });
            //7. Подарок судьбы	007
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 7,
                                            VideoTitle = "Подарок судьбы",
                                            VideoDescription = "",
                                            YoutubeGuid = "Rc84ZglMJVY",
                                            IconUrl = "/Content/images/albums/dvd02/podarok-sudby.jpg",
                                        });
            //8. Фанерное солнце	003
            context.Videos.Add(new YoutubeVideo
                                        {
                                            EpisodeNo = 3,
                                            VideoTitle = "Фанерное солнце",
                                            VideoDescription = "",
                                            YoutubeGuid = "oC27Mz_0r2A",
                                            IconUrl = "/Content/images/albums/dvd02/fanernoe-solntse.jpg",
                                        });

            context.SaveChanges();

            //and now that all the records are added, seed the album videos
            YoutubeVideo[] videos = context.Videos.ToArray();
            VideoAlbum[] albums = context.Albums.ToArray();
            //initialize the first album

            for (int albumIdx = 0; albumIdx < albums.Length; albumIdx++)
            {
                for (int videoIdx = 8 * albumIdx; videoIdx < 8 * albumIdx + 8; videoIdx++)
                {
                    context.AlbumVideos.Add(new AlbumVideo { VideoAlbum = albums[albumIdx], YoutubeVideo = videos[videoIdx] });
                }

            }

            context.SaveChanges();

            base.Seed(context);
        }
    }
}